package com.pdstudio.carrecom.ui.adapter.owner;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.pdstudio.carrecom.R;
import com.pdstudio.carrecom.bean.Boutique;
import com.pdstudio.carrecom.bean.HomeInfo;
import com.pdstudio.carrecom.bean.Order;
import com.pdstudio.carrecom.bean.owner.News;
import com.pdstudio.carrecom.tools.ImageUtil;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 
 * 类: BoutiqueListAdapter <br>
 * 描述: 消息中心 <br>
 * 作者: ws <br>
 * 时间: 2015-5-25 下午11:22:35
 */
public class NewsListAdapter extends BaseAdapter {

	private Context mContext;
	private List<News> mNews;
	private LayoutInflater mInflater;

	public NewsListAdapter(Context context, List<News> news) {
		mContext = context;
		mNews = news;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return mNews.size();
	}

	@Override
	public Object getItem(int i) {
		return mNews.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {

		ViewHolder viewHolder;

		if (view == null) {
			viewHolder = new ViewHolder();
			view = mInflater.inflate(R.layout.item_listview_owner_newscenter,
					viewGroup, false);
			viewHolder.mTitle = (TextView) view
					.findViewById(R.id.boutique_title);
			viewHolder.mName = (TextView) view.findViewById(R.id.boutique_name);
			viewHolder.mPrice = (TextView) view
					.findViewById(R.id.boutique_price);
			viewHolder.mDesc = (TextView) view.findViewById(R.id.boutique_desc);
			viewHolder.mImage=(ImageView) view.findViewById(R.id.img);

			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) view.getTag();
		}

		viewHolder.mTitle.setText(mNews.get(i).type);
		viewHolder.mName.setText(mNews.get(i).status);
		viewHolder.mPrice.setText(mNews.get(i).date);
		try {
			viewHolder.mDesc.setText(java.net.URLDecoder.decode(mNews.get(i).content,"utf-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		ImageUtil.DisplayImage(mNews.get(i).url, viewHolder.mImage);
		
		switch (mNews.get(i).status) {
		case "新消息":
			viewHolder.mName.setTextColor(Color.parseColor("#ff4040"));
			break;
		case "正在处理":
			viewHolder.mName.setTextColor(Color.parseColor("#27c781"));
		default:
			viewHolder.mName.setTextColor(Color.BLACK);
			break;
		}
		return view;
	}

	class ViewHolder {
		private TextView mTitle;
		private TextView mName;
		private TextView mPrice;
		private TextView mDesc;
		private ImageView mImage;
	}
}
